package com.message.api.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.message.api.base.dao.EnAttachmentMapper;
import com.message.api.base.entity.EnAttachment;
import com.message.api.base.service.EnAttachmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mzl
 * @since 2020-07-17
 */
@Service
public class EnAttachmentServiceImpl extends ServiceImpl<EnAttachmentMapper, EnAttachment> implements EnAttachmentService {

    @Override
    public List<EnAttachment> list(EnAttachment example) {
        return this.list(buildWrapper(example));
    }

    @Override
    public IPage<EnAttachment> page(EnAttachment example, IPage page) {
        return this.page(page, buildWrapper(example));
    }

    @Override
    public EnAttachment findByCode(String code) {
        return this.baseMapper.findByCode(code);
    }

    @Override
    public List<EnAttachment> findByIds(List<Integer> ids) {
        QueryWrapper<EnAttachment> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .in(EnAttachment::getId, ids)
                .orderByDesc(EnAttachment::getId);
        return super.list(wrapper);
    }

    @Override
    public Boolean removeByIds(List<Integer> ids) {
        QueryWrapper<EnAttachment> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .in(EnAttachment::getId, ids);
        return super.remove(wrapper);
    }

    private QueryWrapper<EnAttachment> buildWrapper(EnAttachment example) {
        QueryWrapper<EnAttachment> wrapper = new QueryWrapper<>(example);
        wrapper.lambda().orderByDesc(EnAttachment::getId);
        return wrapper;
    }

}
